package com.mayi.zds.service.imp;

import com.mayi.zds.dao.BusinessDAO;
import com.mayi.zds.dao.OrderDAO;
import com.mayi.zds.dao.UserDAO;
import com.mayi.zds.service.RiderService;
import com.mayi.zds.vo.ResponseVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.core.ParameterizedTypeReference;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Service;
import org.springframework.web.client.RestTemplate;

/**
 * @ClassName SedkillServiceImp
 * @Author zhong
 * @Date 2019/12/14 16:51:04
 * @Version 1.0
 */
@Service
public class RiderServiceImp implements RiderService {
    @Autowired
    private RestTemplate restTemplate;

    @Autowired
    private OrderDAO orderDAO;

    @Autowired
    private BusinessDAO businessDAO;

    @Autowired
    private UserDAO userDAO;


    /**
     * 发请求给骑手服务器
     *
     * @param OrderId 订单ID
     * @return void
     * @Author zhong
     * @Date 2019/12/26 16:35:18
     **/
    @Override
    public void sendOrderToRiderServer(String orderId) {
        String url = "http://ckzshop.qicp.vip/rider/newOrder/"+orderId;
        ParameterizedTypeReference<ResponseVO> typeRef = new ParameterizedTypeReference<ResponseVO>() {};
//        Order order = orderDAO.getById(OrderId);
//        Business business = businessDAO.getByid(order.getBusinessId());
//        User user = userDAO.getUserById(order.getUserId());
//
//        Order order = new Order();
//        order.setId(OrderId);
//        order.setOrderNo("订单编号：10000001010");
//        Business business = new Business();
//        business.setId(ZdsUtils.produceId());
//        business.setAddress("四川省 成都市 双流区 孵化园");
//        User user = new User();
//        user.setId(ZdsUtils.produceId());
//        user.setAccount("zhong");

       // ResponseEntity<ResponseVO> responseEntity = restTemplate.exchange(url, HttpMethod.GET, null, typeRef);
        ResponseEntity<ResponseVO> responseEntity = restTemplate.postForEntity(url, null, ResponseVO.class);
        ResponseVO responseVO = responseEntity.getBody();

        System.out.println(responseVO.getCode());
    }
}
